module(..., package.seeall)

require "myUiWin"

PAGEID = 0
local backColor = 0x0000 -- 背景色
local action
local counts
local test_mode = false


local function show()
    disp.setbkcolor(backColor)
    disp.clear()
    -- 画标题底色
    disp.drawrect(0, 25, 105, 27, 0x017E)
    disp.drawrect(110, 25, 160, 27, 0x06C0)
    disp.setcolor(0xFFFF)

    disp.puttext(common.utf8ToGb2312("485透传模式"),
                 ui_handle.getXPos(common.utf8ToGb2312("485透传模式")), 1)

    if nvm.get("TRANSMIT_MODE") then
        disp.puttext(common.utf8ToGb2312("当前状态：开启"),
                     ui_handle.getXPos(
                         common.utf8ToGb2312("当前状态：开启")) - 28, 53)
        disp.putimage("/lua/on.png", 120, 53)

    else
        disp.puttext(common.utf8ToGb2312("当前状态：关闭"),
                     ui_handle.getXPos(
                         common.utf8ToGb2312("当前状态：关闭"))- 28, 53)
                         disp.putimage("/lua/off.png", 120, 53)

    end

    disp.puttext(common.utf8ToGb2312("按"), 40, 90)

    if not nvm.get("TRANSMIT_MODE") then
        disp.puttext(common.utf8ToGb2312("开启"), 90, 90)
    else
        disp.puttext(common.utf8ToGb2312("关闭"), 90, 90)
    end
    disp.putimage("/lua/enter.png", 63, 88)

    disp.update()
end

function initPage(para) show() end

function refresh() show() end

function onKey(value)
    if value == "return" then
        myUiWin.openWin(ui_menu.PAGEID)
    elseif value == "enter" then
        local now = not nvm.get("TRANSMIT_MODE")
        nvm.set("TRANSMIT_MODE", now)
    end
end
